package com.example.exceltosqlite.ui.sqldao;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.example.exceltosqlite.entity.SqliteFileTypeEntity;

import java.util.ArrayList;
import java.util.List;

public class SpinnerTypeAdapter extends BaseAdapter {
    private Context context;

    public SpinnerTypeAdapter(Context context) {
        this.context = context;
    }

    private List<SqliteFileTypeEntity> items = new ArrayList<>();

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public List<SqliteFileTypeEntity> getItems() {
        return items;
    }

    public void setItems(List<SqliteFileTypeEntity> items) {
        if(null == items){
            items.clear();
        }else{
            this.items = items;
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int p, View v, ViewGroup parent) {
        SpinnerTypeItemview spinnerTypeItemview;
        if(null == v){
            spinnerTypeItemview = new SpinnerTypeItemview(context);
        }else{
            spinnerTypeItemview = (SpinnerTypeItemview) v;
        }
        spinnerTypeItemview.bind(items.get(p));
        return spinnerTypeItemview;
    }
}
